package com.forestar.mapControl;

import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity;
import androidx.core.app.ActivityCompat;

import android.Manifest;
import android.content.pm.PackageManager;
import android.os.Bundle;
import android.os.Environment;
import android.util.Log;

import com.forestar.mapControl.mapGeo.InitGISCore;
import com.forestar.mapControl.mapview.TestTextureView2;
import com.forestar.mapControl.utils.LogD;
import com.mapzone.api.InitialSo;

import java.util.Arrays;

/**
 * 展示首页
 */
public class MainActivity extends AppCompatActivity {

    private TestTextureView2 testTextureView;

    final String[] CAMERAS = new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE,
            Manifest.permission.READ_EXTERNAL_STORAGE,Manifest.permission.CAMERA};

    /**
     * 检查出发现授权失败的就返回并进行授权
     *
     * @return
     */
    private String checkPermissionForRequestCamera() {
        for (int i = 0; i < CAMERAS.length; i++) {
            if (ActivityCompat.checkSelfPermission(this, CAMERAS[i]) != PackageManager.PERMISSION_GRANTED) {
                return CAMERAS[i];
            }
        }
        return null;
    }


    private int requestTag = 101;

    @Override
    public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
        super.onRequestPermissionsResult(requestCode, permissions, grantResults);
        LogD.d( "获取权限结果" + Arrays.toString(permissions) + " Granted");
//        if (requestCode == requestTag) {
//            String forRequestCamera = checkPermissionForRequestCamera();
//            if (null != forRequestCamera) {
//                //权限失败  申请权限
//                ActivityCompat.requestPermissions(this, CAMERAS, requestTag);
//            } else {
//            }
//        }
    }
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
//初始化so库（这里面居然有内核so）
        InitialSo.LoadLib();

        testTextureView = new TestTextureView2(this);
        setContentView(testTextureView);
//        setContentView(R.layout.activity_main);

        ActivityCompat.requestPermissions(this, CAMERAS, requestTag);

        InitGISCore.setSpatialRefPath(Environment.getExternalStorageDirectory().getAbsolutePath());// 设置空间参考系配置文件的路径
        InitGISCore.setDataBackupPath(Environment.getExternalStorageDirectory().getAbsolutePath());// 设置备份数据库（模板）路径
//        textTexture = findViewById(R.id.textTexture);
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
    }
}
